#include<stdio.h>

// This class contains all the material variables necessary for the simulation.
// Each material variable has three values, e.g. Eg0, Eg1 and Eg2 for the band-gap.
// For the material A(y)B(x)C(1-x)(1-y)D, Eg0 is the band-gap for material CD, Eg1 is for BD
// Eg2 is for AD. The result is obtained by linear interpolation.
// Some parameters depends on the kind of alloy, e.g. the bowing parameter.
// In this case there are only two values: bowing0 for the BCD material and bowing1 for ACD.
// by Diego Oriato

class Alloy_var {

 protected:

  double Eg0; // Energy band-gap (eV)
  double Eg1; 
  double Eg2;
  double bowing0;  // Bowing parameter for the energy gap (eV)
  double bowing1;
  double cb_offset0;  // Conduction band offset between the two materials as fraction of the band-gap
  double cb_offset1;
  double eps0;  // Relative dielectric constant. (unit of EPS0).
  double eps1;
  double eps2;
  double Nc0;  // Effective density of states in conduction band (cm^-3)
  double Nc1;
  double Nc2;
  double Nv0;  // Effective density of states in valence band (cm^-3)
  double Nv1;
  double Nv2;
  double me0;  // Effective electron mass in unit of the electron mass.
  double me1;
  double me2;
  double mh0;  // Effective hole mass in unit of the electron mass.
  double mh1;
  double mh2;
  double mob_n0;  // Electron Mobility  (cm^2/Vs)
  double mob_n1;
  double mob_n2;
  double mob_p0;  // Hole Mobility  (cm^2/Vs)
  double mob_p1;
  double mob_p2;
  double Tn0;  // Electron recombination time (s)
  double Tn1;
  double Tn2;
  double Tp0;  // Hole recombination time (s)
  double Tp1;
  double Tp2;
  double a0;   // In-plane lattice constant  (amstrong)
  double a1;
  double a2;
  double c0;   // c-axis lattice constant  (amstrong)
  double c1;
  double c2;
  double e33_0;  // Piezoelectric tensor component in c-direction (C/m^2)
  double e33_1;
  double e33_2;
  double e31_0;  // Piezoelectric tensor component in-plane
  double e31_1;
  double e31_2;
  double poisson_ratio_0;  // Poisson's ration  nu/(1-nu)=C13/C33
  double poisson_ratio_1;
  double poisson_ratio_2;
  double Psp0;	// Spontaneous Polarization 
  double Psp1;
  double Psp2;
  double Edon_ion;  // Ionization energy for donors  (eV)
  double Eacc_ion;  // Ionization energy for acceptors (eV)
  double Ntraps;  // Density of electron traps  (cm^-3) 
  double Ptraps;  // Density of hole traps  (cm^-3) 
  double Etraps_e;  // Ionization energy for electron traps  (eV)
  double Etraps_h;  // Ionization energy for hole traps  (eV)
  double Tntraps;  // recombination time for electron traps (s)
  double Tptraps;   // recombination time for hole traps (s)

 public:

  Alloy_var(char * file,double,double);
  void show();


  double Eg(double x,double y) {return ((Eg1*x+Eg0*(1.0-x)+bowing0*(1.0-x)*x)*(1.0-y)+Eg2*y+bowing1*(1.0-y)*y);}
  double chi(double x,double y){return cb_offset0*(Eg0-Eg(x,0))+cb_offset1*(Eg0-Eg(0,y));}
  double eps(double x,double y){return (eps1*x+eps0*(1.0-x))*(1.0-y)+y*eps2;}
  double Nc(double x,double y)	{return (Nc1*x+Nc0*(1.0-x))*(1.0-y)+y*Nc2;}
  double Nv(double x,double y)	{return (Nv1*x+Nv0*(1.0-x))*(1.0-y)+y*Nv2;}
  double me(double x,double y)	{return (me1*x+me0*(1.0-x))*(1.0-y)+y*me0;}
  double mh(double x,double y)	{return (mh1*x+mh0*(1.0-x))*(1.0-y)+y*mh0;}
  double mob_n(double x,double y){return (mob_n1*x+mob_n0*(1.0-x))*(1.0-y)+y*mob_n2;}
  double mob_p(double x,double y) {return (mob_p1*x+mob_p0*(1.0-x))*(1.0-y)+y*mob_p2;}
  double Dn(double x,double y) {return 0.025*mob_n(x,y);}
  double Dp(double x,double y) {return 0.025*mob_p(x,y);}
  double Tn(double x,double y)	{return (Tn1*x+Tn0*(1.0-x))*(1.0-y)+y*Tn2;}
  double Tp(double x,double y)	{return (Tp1*x+Tp0*(1.0-x))*(1.0-y)+y*Tp2;}
  double a(double x,double y)	{return (a1*x+a0*(1.0-x))*(1.0-y)+y*a2;}
  double c(double x,double y)   {return (c1*x+c0*(1.0-x))*(1.0-y)+y*c2;}
  double e33(double x,double y)	{return (e33_1*x+e33_0*(1.0-x))*(1.0-y)+y*e33_2;}
  double e31(double x,double y)	{return (e31_1*x+e31_0*(1.0-x))*(1.0-y)+y*e31_2;}
  double poisson_ratio(double x,double y){
    return (poisson_ratio_1*x+poisson_ratio_0*(1.0-x))*(1.0-y)+y*poisson_ratio_2;}
  double Psp(double x,double y)	{return (((Psp1*x+Psp0*(1.0-x)))*(1.0-y)+y*Psp2);}
  double Eion(double doping) {return (doping>0)?Edon_ion:Eacc_ion;}
  double Etrap_e() {return Etraps_e; }
  double Ntrap() {return Ntraps; }
  double Etrap_h() {return Etraps_h; }
  double Ptrap() {return Ptraps; }
  double Tntrap() {return Tntraps; }
  double Tptrap() {return Tptraps; }
  void notraps() { Ntraps = 0; Etraps_e = 0; Ptraps = 0; Etraps_h = 0; Tntraps = 0; Tptraps = 0; }

  double Pz(double x, double y, double a_inp, double c_inp) {
    if(a_inp==0 || c_inp==0) return 0.0;
    else return ( e33(x,y)*((c_inp/c(x,y))-1.0 )+ 2.0*e31(x,y)*( (a_inp/a(x,y))-1.0 ) );
  }


};



















